home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
386
/
utility
/
spawn.s
< prev
next >
Wrap
Text File
|
1985-11-19
|
4KB
|
94 lines
; Program Name: SPAWN.S
; Version 1.003
; Assembly Instructions:
; Assemble in "PC-relative" mode and save with a TTP extension.
; Program Function:
; Spawn the TOS or PRG process typed on the command line. Create a disk
; file which is to be identified by the name of the spawned program with a
; DAT suffix. The disk file is to reside in the same directory as does the
; spawned process.
; If the program to be executed has any halt or wait instructions, such
; as wait for a keypress, etc., you must remember that execution of the
; spawned process will not terminate until those conditions are satisfied.
release_excess_memory:
lea -$82(pc), a3 ; Put "command line" address in A3.
lea -$80(a3), a1 ; Put "basepage" address in A1.
lea program_end, a0 ; Put "end of program" address in A0.
trap #6 ; Calculate program size and release memory.
lea stack, a7 ; Point A7 to this program's stack.
process_command_line_parameters:
lea command_line, a4 ; Fetch location to contain command line.
movem.l (a3), d0-d3 ; Move 16 bytes of command line to 4 registers.
movem.l d0-d3, (a4) ; Move them to address "command_line".
move.b (a3)+, d0 ; Fetch command line ASCII character count.
ext.w d0 ; Extend to word for next instruction.
move.b #0, 1(a4,d0.w) ; Store a null at end of string.
lea program_name, a0 ; Fetch address of pointer to command line.
move.l a3, (a0) ; Store address of command line string at
; pointer.
move.b #0, 0(a3,d0.w) ; Replace $0D at end of command line input
; in basepage with a NULL.
insert_filename_suffix:
move.b #$44, -2(a4,d0.w) ; Insert letter 'D'.
move.b #$41, -1(a4,d0.w) ; Insert letter 'A'.
move.b #$54, 0(a4,d0.w) ; Insert letter 'T'.
create_file:
move.w #0, -(sp) ; File attribute = read/write.
pea filename ; Will be name of spawned process + .DAT.
move.w #$3C, -(sp) ; Function = f_create = GEMDOS $3C.
trap #1 ; File handle is returned in D0.
addq.l #8, sp
lea file_handle, a0 ; Store returned file handle to be used when
move.w d0, (a0) ; the file is closed later.
redirect_output: ; Exchange file handle with screen's handle.
move.w d0, -(sp) ; This is the disk file's handle.
move.w #1, -(sp) ; This is the video screen's handle.
move.w #$46, -(sp) ; Function = f_force = GEMDOS $46.
trap #1
addq.l #6, sp
load_and_execute_program:
pea environ_string
pea command_string
pea (a3) ; A3 contains address of program name string.
move.w #0, -(sp) ; Load and Go option.
move.w #$4B, -(sp) ; Function = GEMDOS $4B = p_exec.
trap #1
lea $10(a7), sp ; Reposition stack pointer.
close_file:
move.w file_handle, -(sp)
move.w #$3E, -(sp) ; Function = GEMDOS $3E = f_close.
trap #1
addq.l #4, sp
terminate:
move.w #0, -(sp)
trap #1
data
environ_string: dc.b "TERM",0
command_string: dc.b 0
align
bss
file_handle: ds.w 1 ; Handle for the disk file named below.
command_line: ds.b 1 ; Unused character count will go here.
filename: ds.b 15 ; File name for redirected output.
program_name: ds.l 1 ; Pointer to name in basepage command line.
ds.l 96 ; Program stack.
stack: ds.l 0 ; Address of program stack.
program_end: ds.l 0
end